package com.spareparts.activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.spareparts.R;
import com.spareparts.activity.base.BaseActivityGroup;
import com.spareparts.util.Content;

public class WarehouseRKActivity extends BaseActivityGroup 
{
	private TextView mStorageTextView;
	private TextView mBackTextView;
	private TextView mInventoryTextView;
	
	private LinearLayout mContainer;
	private LocalActivityManager manager;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		requestWindowFeature( Window.FEATURE_NO_TITLE );
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_warehouse_rk);

		mStorageTextView = (TextView) findViewById(R.id.buttonStorage);
		mBackTextView = (TextView) findViewById(R.id.buttonBack);
		mInventoryTextView = (TextView) findViewById(R.id.buttonInventory);
		
		mContainer = (LinearLayout) findViewById(R.id.container);
		manager=getLocalActivityManager();
		
		setTextViewOnClick();
		
		mCommonApplication.mContext = this;
		
		setIntent(Content.STORAGE_CLICK);
	}
	
	
	/**
	 * 设置单击事件
	 */
	private void setTextViewOnClick()
	{
		mStorageTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(Content.STORAGE_CLICK);
			}
		});
		
		mBackTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(Content.BACK_CLICK);
			}
		});
		
		mInventoryTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(Content.INVENTORY_CLICK);
			}
		});
	}
	
	/**
	 * 设置跳转事件
	 */
	private void setIntent(int num)
	{
		 // 点击前所有的textview的状态设为没有点击
		 mStorageTextView.setBackgroundResource(R.drawable.top_button_small);
		 mStorageTextView.setTextColor(mContext.getResources().getColor(R.color.white));
		 mBackTextView.setBackgroundResource(R.drawable.top_button_small);
		 mBackTextView.setTextColor(mContext.getResources().getColor(R.color.white));
		 mInventoryTextView.setBackgroundResource(R.drawable.top_button_small);
		 mInventoryTextView.setTextColor(mContext.getResources().getColor(R.color.white));
		
		 // 设置跳转
		 if(num == Content.STORAGE_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_0",
						new Intent(mContext, WareHouseStorageActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
						.putExtra("type", Content.STORAGE_CLICK)).getDecorView());
			 
			 mStorageTextView.setBackgroundResource(R.drawable.top_button_small_onclick);
			 mStorageTextView.setTextColor(mContext.getResources().getColor(R.color.title_font_color));
		 }
		 else if(num == Content.BACK_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_5",
						new Intent(mContext, WareHouseStorageActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
						.putExtra("type", Content.BACK_CLICK)).getDecorView());
			 
			 mBackTextView.setBackgroundResource(R.drawable.top_button_small_onclick);
			 mBackTextView.setTextColor(mContext.getResources().getColor(R.color.title_font_color));
		 }
		 else if(num == Content.INVENTORY_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_6",
						new Intent(mContext, WareHouseStorageActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
						.putExtra("type", Content.INVENTORY_CLICK)).getDecorView());
			 
			 mInventoryTextView.setBackgroundResource(R.drawable.top_button_small_onclick);
			 mInventoryTextView.setTextColor(mContext.getResources().getColor(R.color.title_font_color));
		 }
	}
}
